﻿using System.ComponentModel;
using System.Windows.Input;

namespace Vtron.HipcConfigurationTools
{
    public class AddCodecViewModel : INotifyPropertyChanged
    {
        private ICommand addCodecCommand;
        //private ICommand addCommand;

        public AddCodecViewModel()
        {
            addCodecCommand = new DelegateCommand<string>(AddCodec);
            //addCommand = new DelegateCommand<string>(Connect);
        }

        public ICommand AddCodecCommand { get { return addCodecCommand; } }
        //public ICommand AddCommand { get { return addCommand; } }

        private void AddCodec(string codecIp)
        {
            MainWindow mainWindow = App.Current.Windows[0] as MainWindow;
            //if (codecType == CodecType.Encoded)
            //{
            //    mainWindow.EncodedViewModel.CodecInfoes.Add(new CodecInfo() { Ip = codecIp, SignalType = EncodedType.ToString(), CodecType = "编码器" });
            //    mainWindow.CodecTab.SelectedIndex = 0;

            //    mainWindow.SaveCodec();
            //}
            //else
            //{
            //    mainWindow.DecodeViewModel.CodecInfoes.Add(new CodecInfo() { Ip = codecIp, SignalType = EncodedType.ToString(), CodecType = "解码器" });
            //    mainWindow.CodecTab.SelectedIndex = 1;

            //    mainWindow.SaveCodec();
            //}

            if (codecType == CodecType.Encoded)
            {
                mainWindow.CodecListViewModel.CodecInfoes.Add(new CodecInfo() { Index = mainWindow.CodecListViewModel.CodecInfoes.Count + 1, Ip = codecIp, SignalType = EncodedType.ToString(), CodecType = "编码器" });
            }
            else
            {
                mainWindow.CodecListViewModel.CodecInfoes.Add(new CodecInfo() { Index = mainWindow.CodecListViewModel.CodecInfoes.Count + 1, Ip = codecIp, SignalType = EncodedType.ToString(), CodecType = "解码器" });
            }
            mainWindow.SaveCodec();
        }

        //private void Connect(string obj)
        //{
        //    MainWindow mainWindow = App.Current.Windows[0] as MainWindow;
        //    mainWindow.ShowDetails();
        //}

        private EncodedType encodedType;

        public EncodedType EncodedType
        {
            get { return encodedType; }
            set
            {
                encodedType = value;

                if (PropertyChanged != null)
                {
                    PropertyChanged.Invoke(this, new PropertyChangedEventArgs("EncodedType"));
                }
            }
        }

        private CodecType codecType;

        public CodecType CodecType
        {
            get { return codecType; }
            set
            {
                codecType = value;

                if (PropertyChanged != null)
                {
                    PropertyChanged.Invoke(this, new PropertyChangedEventArgs("CodecType"));
                }
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}
